Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maven Wrapper mvnw and mvnw.cmd built-in support #246

Closed
wants to merge 3 commits into from

Conversation

nhojpatrick
Copy link
Contributor

If mvnExecutable is blank, then automatically use mvnw or mvnw.cmd depending upon OS, if avaliable.

Tested on Mac, that if mvnw is present then the current working directory will be used instead of just mvn.

@aleksandr-m
Copy link
Owner

@nhojpatrick Have you tested this on Windows? I remember that there were some problems executing mvn.cmd instead of mvn on Windows.

@nhojpatrick
Copy link
Contributor Author

@aleksandr-m tested on a windows 10 vm that didn't have mvn installed/setup, using Command Prompt

C:\john\aleksandr-m_gitflow-maven-plugin>mvnw com.amashchenko.maven.plugin:gitflow-maven-plugin:1.14.1-SNAPSHOT:release -DpostReleaseGoals=deploy
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< com.amashchenko.maven.plugin:gitflow-maven-plugin >----------
[INFO] Building gitflow-maven-plugin 1.14.1
[INFO] ----------------------------[ maven-plugin ]----------------------------
[INFO]
[INFO] --- gitflow-maven-plugin:1.14.1-SNAPSHOT:release (default-cli) @ gitflow-maven-plugin ---
[INFO] Checking for uncommitted changes.
[INFO] Fetching remote branch 'origin develop'.
[WARNING] There were some problems fetching remote branch 'origin develop'. You can turn off remote branch fetching by setting the 'fetchRemote' parameter to false.
[INFO] Fetching remote branch 'origin master'.
[INFO] Comparing local branch 'master' with remote 'origin/master'.
[INFO] Checking out 'develop' branch.
[INFO] Checking for SNAPSHOT versions in dependencies.
[INFO] Cleaning and testing the project.
What is release version? [1.14.1]:
[INFO] Version is blank. Using default version.
[INFO] Checking out 'master' branch.
[INFO] Merging (--no-ff) 'develop' branch.
[INFO] Creating '1.14.1' tag.
[INFO] Running Maven goals: deploy
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  47.233 s
[INFO] Finished at: 2020-09-05T22:27:01+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.amashchenko.maven.plugin:gitflow-maven-plugin:1.14.1-SNAPSHOT:release (default-cli) on project gitflow-maven-plugin: release: [INFO] Scanning for projects...
[ERROR] [INFO]
[ERROR] [INFO] ---------< com.amashchenko.maven.plugin:gitflow-maven-plugin >----------
[ERROR] [INFO] Building gitflow-maven-plugin 1.14.1
[ERROR] [INFO] ----------------------------[ maven-plugin ]----------------------------
...
...
...
[ERROR] [INFO] ------------------------------------------------------------------------
[ERROR] [INFO] BUILD FAILURE
[ERROR] [INFO] ------------------------------------------------------------------------
[ERROR] [INFO] Total time:  12.125 s
[ERROR] [INFO] Finished at: 2020-09-05T22:27:01+01:00
[ERROR] [INFO] ------------------------------------------------------------------------
[ERROR] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project gitflow-maven-plugin: Failed to deploy artifacts: Could not transfer artifact com.amashchenko.maven.plugin:gitflow-maven-plugin:jar:1.14.1 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Transfer failed for https://oss.sonatype.org/service/local/staging/deploy/maven2/com/amashchenko/maven/plugin/gitflow-maven-plugin/1.14.1/gitflow-maven-plugin-1.14.1.jar 401 Unauthorized -> [Help 1]
[ERROR] [ERROR]
[ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] [ERROR]
[ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Which errors because deploy doesn't have a valid username and password to actually upload as part of the deploy phase. So it must have found mvnw.cmd.

@aleksandr-m
Copy link
Owner

@nhojpatrick Can it be done in that way to use the same maven which user currently uses to run this plugin?
Something like if mvnExecutable is blank then see which maven had started plugin if wrapper then use it, if not then use the default.

@nhojpatrick
Copy link
Contributor Author

@nhojpatrick Can it be done in that way to use the same maven which user currently uses to run this plugin?
Something like if mvnExecutable is blank then see which maven had started plugin if wrapper then use it, if not then use the default.

Using mavenSession.getSystemProperties() you can use;

  • env.JAVA_MAIN_CLASS_<PID>=org.apache.maven.wrapper.MavenWrapperMain vs env.JAVA_MAIN_CLASS_<PID>=org.codehaus.plexus.classworlds.launcher.Launcher
  • maven.home=/usr/local/Cellar/maven/3.6.3_1/libexec vs maven.home=/Users/USERNAME/.m2/wrapper/dists/apache-maven-3.6.3-bin/HASH/apache-maven-3.6.3

So @aleksandr-m any preference in a pattern match for env key env.JAVA_MAIN_CLASS_* with value org.apache.maven.wrapper.MavenWrapperMain, or key maven.home with value pattern .*/wrapper/dists/.*?

Working on testing both but it looks like both approaches can be used on a mac using maven 3.6.3.

@nhojpatrick
Copy link
Contributor Author

nhojpatrick commented Jan 17, 2021

@aleksandr-m decided to use both main class check and maven home check to determine if triggered by mvnw.

I think this is now ready to be merged.

Also noticed extra config for maven-compiler-plugin, so use my goto global properties defaults for any maven project.

@nhojpatrick
Copy link
Contributor Author

@aleksandr-m have done some more testing and believe it works on both linux and windows, as well for builds within openshift and other cicd tools that default to mvnw if it's present.

@nhojpatrick
Copy link
Contributor Author

@aleksandr-m want to add you as a reviewer and request a review but don't have permissions to do that.

@nhojpatrick
Copy link
Contributor Author

@aleksandr-m Could this be reviewed and hopefully merged please.

@aleksandr-m
Copy link
Owner

@nhojpatrick Can you revert changes to properties. I'm more comfortable with them as they are now. I'll try to find time to review this in a few days.

@aleksandr-m aleksandr-m self-requested a review September 11, 2021 09:07
Copy link
Owner

@aleksandr-m aleksandr-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nhojpatrick I don't see any env.JAVA_MAIN_CLASS in my setup, so mainClassIsMavenWrapper is always false. And the maven.home property can be overridden from the command line.
Can you think of any other way to determine if goal is running from the wrapper?

@aleksandr-m
Copy link
Owner

@nhojpatrick I had more time to test this feature, and seems using sun.java.command property works fine, at least in oracle/openjdk. See 72da507. Thanks for the idea and initial code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants